package org.vectrics.recruiter.hibernate;

import org.apache.log4j.Logger;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
import org.vectrics.batch.BatchInfo;
import org.vectrics.batch.BatchLog;
import org.vectrics.cms.CmsSection;
import org.vectrics.common.db.PropertyType;
import org.vectrics.common.db.SurrogateKey;
import org.vectrics.common.reporting.Report;
import org.vectrics.company.Company;
import org.vectrics.company.CompanyAddress;
import org.vectrics.company.CompanyAddressType;
import org.vectrics.company.CompanyPerson;
import org.vectrics.company.CompanyPersonGroup;
import org.vectrics.company.CompanyPersonGroupType;
import org.vectrics.company.CompanyPersonRole;
import org.vectrics.company.CompanyPersonRoleType;
import org.vectrics.company.SalaryType;
import org.vectrics.company.Sector;
import org.vectrics.cv.Area;
import org.vectrics.cv.Career;
import org.vectrics.cv.CompanyActivity;
import org.vectrics.cv.Department;
import org.vectrics.cv.Experience;
import org.vectrics.cv.ExtraCertificate;
import org.vectrics.cv.Hierarchy;
import org.vectrics.cv.Language;
import org.vectrics.cv.Level;
import org.vectrics.cv.PersonLanguage;
import org.vectrics.cv.PersonSkill;
import org.vectrics.cv.Studies;
import org.vectrics.cv.StudyType;
import org.vectrics.cv.University;
import org.vectrics.domain.Domain;
import org.vectrics.domain.HtmlCssEntry;
import org.vectrics.domain.HtmlFormType;
import org.vectrics.domain.Phrase;
import org.vectrics.employee.EmployeeStatus;
import org.vectrics.employee.HealthInsurance;
import org.vectrics.employee.JobTermReference;
import org.vectrics.evaluation.EvaluationType;
import org.vectrics.event.Event;
import org.vectrics.event.EventAttachment;
import org.vectrics.event.EventType;
import org.vectrics.hibernate.HibernateUtil;
import org.vectrics.history.Activity;
import org.vectrics.history.ActivityType;
import org.vectrics.history.AuditLogRecord;
import org.vectrics.location.Address;
import org.vectrics.location.Country;
import org.vectrics.location.DomainLocation;
import org.vectrics.location.Locale;
import org.vectrics.location.Location;
import org.vectrics.location.LocationType;
import org.vectrics.location.PostalCodeLocation;
import org.vectrics.mail.FileEmailTemplate;
import org.vectrics.mail.FileEmailTemplateCategory;
import org.vectrics.project.task.Task;
import org.vectrics.project.task.TaskAttachment;
import org.vectrics.project.task.TaskCategory;
import org.vectrics.project.task.TaskPrerequisite;
import org.vectrics.project.task.TaskResource;
import org.vectrics.project.task.TaskStatus;
import org.vectrics.project.task.TaskStatusType;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.company.RecruitCompanyInfo;
import org.vectrics.recruiter.config.RecruitConfig;
import org.vectrics.recruiter.document.CandidateDocument;
import org.vectrics.recruiter.document.CandidateDocumentCategory;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobCandidate;
import org.vectrics.recruiter.job.JobCandidateCompanyPersonRole;
import org.vectrics.recruiter.job.JobCandidateResult;
import org.vectrics.recruiter.job.JobCandidateStatus;
import org.vectrics.recruiter.job.JobCandidateStatusReasonType;
import org.vectrics.recruiter.job.JobCandidateStatusReasonXref;
import org.vectrics.recruiter.job.JobCandidateStatusType;
import org.vectrics.recruiter.job.JobClassification;
import org.vectrics.recruiter.job.JobFunction;
import org.vectrics.recruiter.job.JobFunctionType;
import org.vectrics.recruiter.job.JobPayType;
import org.vectrics.recruiter.job.JobProperty;
import org.vectrics.recruiter.job.JobSkillRating;
import org.vectrics.recruiter.job.JobStatus;
import org.vectrics.recruiter.job.JobStatusReasonType;
import org.vectrics.recruiter.job.JobStatusReasonTypeXref;
import org.vectrics.recruiter.job.JobStatusSubType;
import org.vectrics.recruiter.job.JobStatusType;
import org.vectrics.recruiter.job.JobStatusTypeApproval;
import org.vectrics.recruiter.job.JobTask;
import org.vectrics.recruiter.job.JobTerm;
import org.vectrics.recruiter.job.JobUserRole;
import org.vectrics.recruiter.job.SearchWord;
import org.vectrics.recruiter.user.CandidateInfo;
import org.vectrics.recruiter.user.CandidateLocation;
import org.vectrics.recruiter.user.Interview;
import org.vectrics.recruiter.user.InterviewInstance;
import org.vectrics.recruiter.user.InterviewResultType;
import org.vectrics.recruiter.user.JobAgent;
import org.vectrics.recruiter.user.JobAgentFunction;
import org.vectrics.recruiter.user.JobAgentLocation;
import org.vectrics.recruiter.user.Resume;
import org.vectrics.recruiter.user.ResumeScanBatch;
import org.vectrics.recruiter.user.ResumeScanBatchJob;
import org.vectrics.recruiter.user.ResumeScanCriteria;
import org.vectrics.recruiter.user.ResumeScanResult;
import org.vectrics.recruiter.user.resume.email.EmailedResumeAttachment;
import org.vectrics.recruiter.user.resume.email.EmailedResumeInfo;
import org.vectrics.recruiter.user.resume.email.EmailedResumeInfoJobCandidate;
import org.vectrics.security.ProtectedResource;
import org.vectrics.security.ProtectedResourceUserPrivilege;
import org.vectrics.security.UserPrivilegeToUserPrivilegeXRef;
import org.vectrics.skill.PersonSkillScore;
import org.vectrics.skill.Skill;
import org.vectrics.skill.SkillScoringMethod;
import org.vectrics.skill.SkillScoringMethodLevel;
import org.vectrics.skill.UserEvaluation;
import org.vectrics.skill.UserSkillRating;
import org.vectrics.system.PagePrivilege;
import org.vectrics.system.PagePrivilegeUserPrivilege;
import org.vectrics.system.SystemConstant;
import org.vectrics.user.CommonFirstName;
import org.vectrics.user.CommonLastName;
import org.vectrics.user.ContactInfo;
import org.vectrics.user.PasswordHintQuestion;
import org.vectrics.user.Person;
import org.vectrics.user.PersonAddress;
import org.vectrics.user.PersonAddressType;
import org.vectrics.user.PersonCommunication;
import org.vectrics.user.PersonCommunicationMethod;
import org.vectrics.user.PersonCommunicationMethodType;
import org.vectrics.user.PersonCommunicationReason;
import org.vectrics.user.PersonCommunicationReasonType;
import org.vectrics.user.PersonEducation;
import org.vectrics.user.PersonEducationType;
import org.vectrics.user.PersonEncounterStatusType;
import org.vectrics.user.PersonInfo;
import org.vectrics.user.PersonPrivilegeGroup;
import org.vectrics.user.PersonPrivilegeGroupAssignRights;
import org.vectrics.user.PersonPrivilegeGroupRole;
import org.vectrics.user.PersonPrivilegeGroupType;
import org.vectrics.user.PersonProperty;
import org.vectrics.user.ServiceRequest;
import org.vectrics.user.User;
import org.vectrics.user.UserPrivilege;
import org.vectrics.user.UserPrivilegeType;
import org.vectrics.user.UserPrivilegeTypeGroup;

import com.hexacta.hrs.domain.employee.history.AgreementCondition;
import com.hexacta.hrs.domain.employee.history.AssignabilityStatus;
import com.hexacta.hrs.domain.employee.history.CareerRole;
import com.hexacta.hrs.domain.employee.history.EmploymentConditionHistory;
import com.hexacta.hrs.domain.employee.history.MentorAssignment;
import com.hexacta.hrs.domain.exchange.Accrued;
import com.hexacta.hrs.domain.exchange.Confirmation;
import com.hexacta.hrs.domain.exchange.Exchange;
import com.hexacta.hrs.domain.exchange.ExchangeItem;
import com.hexacta.hrs.domain.exchange.Referring;
import com.hexacta.hrs.domain.feedback.ArchivoAdjunto;
import com.hexacta.hrs.domain.feedback.Feedback;
import com.hexacta.hrs.domain.feedback.FeedbackMotive;
import com.hexacta.hrs.domain.feedback.FeedbackPeriod;
import com.hexacta.hrs.domain.feedback.Period;
import com.hexacta.hrs.domain.feedback.skills.FeedbackSkill;
import com.hexacta.hrs.domain.feedback.training.Training;
import com.hexacta.hrs.domain.feedback.training.TrainingOcasion;
import com.hexacta.hrs.domain.mentoring.Action;
import com.hexacta.hrs.domain.mentoring.Meeting;
import com.hexacta.hrs.domain.mentoring.Theme;
import com.hexacta.hrs.domain.staffing.Client;
import com.hexacta.hrs.domain.staffing.Departamento;
import com.hexacta.hrs.domain.staffing.Project;
import com.hexacta.hrs.domain.staffing.Requirement;
import com.hexacta.hrs.domain.staffing.RequirementSkills;
import com.hexacta.hrs.domain.staffing.assignment.EmployeeAssignment;
import com.hexacta.hrs.familiarrelationship.FamiliarRelationship;
import com.hexacta.hrs.securitygroups.Permission;
import com.hexacta.hrs.securitygroups.SecurityGroup;
import com.hexacta.hrs.securitygroups.SecurityPage;
import com.hexacta.hrs.timeoff.AvailableLicenseDays;
import com.hexacta.hrs.timeoff.CompensationDaysAssignation;
import com.hexacta.hrs.timeoff.TimeOff;
import com.hexacta.hrs.timeoff.TimeOffStatusDetail;
import com.hexacta.hrs.timeoff.VacationDaysCalculationDetail;

public class RecruitHibernate extends HibernateUtil {
    private transient static Logger log = Logger.getLogger(RecruitHibernate.class);

    private String testDatabaseUser = "flashrecruit";

    private String testDatabasePassword = "vectrics";

    public RecruitHibernate() {
    }

    public String getTestDatabasePassword() {
        return testDatabasePassword;
    }

    public void setTestDatabasePassword(final String testDatabasePassword) {
        this.testDatabasePassword = testDatabasePassword;
    }

    public String getTestDatabaseUser() {
        return testDatabaseUser;
    }

    public void setTestDatabaseUser(final String testDatabaseUser) {
        this.testDatabaseUser = testDatabaseUser;
    }

    @Override
    public String getDataSource() {
        return RecruitConfig.getRecruitInstance().getDataSourceJndi();
    }

    @Override
    protected void registerMappings(final Configuration cfg) throws MappingException {
        log.debug("Adding class mappings to Hibernate");
        // <!-- Timeoff -->
        cfg.addClass(AvailableLicenseDays.class);
        cfg.addClass(CompensationDaysAssignation.class);
        cfg.addClass(TimeOff.class);
        cfg.addClass(TimeOffStatusDetail.class);
        cfg.addClass(VacationDaysCalculationDetail.class);

        // <!-- Security Groups -->
        cfg.addClass(SecurityGroup.class);
        cfg.addClass(Permission.class);
        cfg.addClass(SecurityPage.class);

        // <!-- Familiar Relationships -->
        cfg.addClass(FamiliarRelationship.class);

        // <!-- Mentoring-->
        cfg.addClass(Meeting.class);
        cfg.addClass(Theme.class);
        cfg.addClass(Action.class);

        // <!-- Staffing -->
        cfg.addClass(Client.class);
        cfg.addClass(Departamento.class);
        cfg.addClass(Requirement.class);
        cfg.addClass(Project.class);
        cfg.addClass(EmployeeAssignment.class);
        cfg.addClass(RequirementSkills.class);
        
        // <!-- Feedback -->
        cfg.addClass(ArchivoAdjunto.class);
        cfg.addClass(FeedbackSkill.class);
        cfg.addClass(Feedback.class);
        cfg.addClass(FeedbackPeriod.class);
        cfg.addClass(FeedbackMotive.class);
        cfg.addClass(Period.class);
        cfg.addClass(TrainingOcasion.class);
        cfg.addClass(Training.class);

        // <!-- Employment History -->
        cfg.addClass(EmploymentConditionHistory.class);
        cfg.addClass(CareerRole.class);
        cfg.addClass(MentorAssignment.class);
        cfg.addClass(AgreementCondition.class);
        cfg.addClass(AssignabilityStatus.class);

        // <!-- HRS V1.0 Mappings -->
        cfg.addClass(Report.class);
        cfg.addClass(FileEmailTemplateCategory.class);
        cfg.addClass(FileEmailTemplate.class);
        cfg.addClass(PersonCommunicationReasonType.class);
        cfg.addClass(PersonCommunicationReason.class);
        cfg.addClass(PersonCommunicationMethodType.class);
        cfg.addClass(PersonCommunicationMethod.class);
        cfg.addClass(PersonCommunication.class);
        cfg.addClass(InterviewResultType.class);
        cfg.addClass(CmsSection.class);
        cfg.addClass(JobCandidateStatusReasonXref.class);
        cfg.addClass(Sector.class);
        cfg.addClass(PersonEducationType.class);
        cfg.addClass(PersonEducation.class);
        cfg.addClass(JobStatusSubType.class);
        cfg.addClass(JobClassification.class);
        cfg.addClass(PersonInfo.class);
        cfg.addClass(JobCandidateStatusReasonType.class);
        cfg.addClass(JobStatusTypeApproval.class);
        cfg.addClass(JobProperty.class);
        cfg.addClass(PersonProperty.class);
        cfg.addClass(PropertyType.class);
        cfg.addClass(CompanyPersonGroupType.class);
        cfg.addClass(CompanyPersonGroup.class);
        cfg.addClass(EmailedResumeInfoJobCandidate.class);
        cfg.addClass(CandidateDocument.class);
        cfg.addClass(LocationType.class);
        cfg.addClass(DomainLocation.class);
        cfg.addClass(PersonPrivilegeGroupAssignRights.class);
        cfg.addClass(PersonPrivilegeGroupRole.class);
        cfg.addClass(PersonPrivilegeGroup.class);
        cfg.addClass(PersonPrivilegeGroupType.class);
        cfg.addClass(JobAgentLocation.class);
        cfg.addClass(JobAgentFunction.class);
        cfg.addClass(CommonFirstName.class);
        cfg.addClass(CommonLastName.class);
        cfg.addClass(JobTask.class);
        cfg.addClass(TaskPrerequisite.class);
        cfg.addClass(TaskAttachment.class);
        cfg.addClass(TaskStatusType.class);
        cfg.addClass(TaskStatus.class);
        cfg.addClass(TaskResource.class);
        cfg.addClass(TaskCategory.class);
        cfg.addClass(Task.class);
        cfg.addClass(EventType.class);
        cfg.addClass(EventAttachment.class);
        cfg.addClass(Event.class);
        cfg.addClass(EmailedResumeInfo.class);
        cfg.addClass(EmailedResumeAttachment.class);
        cfg.addClass(CandidateDocumentCategory.class);
        cfg.addClass(PersonSkillScore.class);
        cfg.addClass(JobCandidateResult.class);
        cfg.addClass(PagePrivilege.class);
        cfg.addClass(PagePrivilegeUserPrivilege.class);
        cfg.addClass(PasswordHintQuestion.class);
        cfg.addClass(ProtectedResource.class);
        cfg.addClass(ProtectedResourceUserPrivilege.class);
        cfg.addClass(UserPrivilegeToUserPrivilegeXRef.class);
        cfg.addClass(JobStatus.class);
        cfg.addClass(Locale.class);
        cfg.addClass(JobStatusReasonType.class);
        cfg.addClass(JobStatusReasonTypeXref.class);
        cfg.addClass(CandidateLocation.class);
        cfg.addClass(SystemConstant.class);
        cfg.addClass(PostalCodeLocation.class);
        cfg.addClass(Country.class);
        cfg.addClass(JobPayType.class);
        cfg.addClass(SalaryType.class);
        cfg.addClass(BatchInfo.class);
        cfg.addClass(BatchLog.class);
        cfg.addClass(UserPrivilegeType.class);
        cfg.addClass(UserPrivilegeTypeGroup.class);
        cfg.addClass(Activity.class);
        cfg.addClass(ActivityType.class);
        cfg.addClass(SurrogateKey.class);
        cfg.addClass(AuditLogRecord.class);
        cfg.addClass(Job.class);
        cfg.addClass(JobCandidateCompanyPersonRole.class);
        cfg.addClass(Address.class);
        cfg.addClass(Location.class);
        cfg.addClass(Company.class);
        cfg.addClass(User.class);
        cfg.addClass(Person.class);
        cfg.addClass(UserPrivilege.class);
        cfg.addClass(ContactInfo.class);
        cfg.addClass(JobCandidate.class);
        cfg.addClass(JobFunction.class);
        cfg.addClass(JobFunctionType.class);
        cfg.addClass(JobStatusType.class);
        cfg.addClass(SearchWord.class);
        cfg.addClass(UserSkillRating.class);
        cfg.addClass(SkillScoringMethod.class);
        cfg.addClass(SkillScoringMethodLevel.class);
        cfg.addClass(JobSkillRating.class);
        cfg.addClass(UserEvaluation.class);
        cfg.addClass(CompanyPerson.class);
        cfg.addClass(CompanyPersonRole.class);
        cfg.addClass(CompanyPersonRoleType.class);
        cfg.addClass(JobTermReference.class);
        cfg.addClass(PersonSkill.class);
        cfg.addClass(ExtraCertificate.class);
        cfg.addClass(org.vectrics.cv.Skill.class);
        cfg.addClass(StudyType.class);
        cfg.addClass(University.class);
        cfg.addClass(JobTerm.class);
        cfg.addClass(EmployeeStatus.class);
        cfg.addClass(HealthInsurance.class);
        cfg.addClass(EvaluationType.class);
        cfg.addClass(Experience.class);
        cfg.addClass(CompanyActivity.class);
        cfg.addClass(Hierarchy.class);
        cfg.addClass(Area.class);
        cfg.addClass(Department.class);
        cfg.addClass(PersonLanguage.class);
        cfg.addClass(Level.class);
        cfg.addClass(Language.class); // TODO a eliminar
        cfg.addClass(Career.class);
        cfg.addClass(Studies.class);
        cfg.addClass(Domain.class);
        cfg.addClass(HtmlCssEntry.class);
        cfg.addClass(HtmlFormType.class);
        cfg.addClass(Phrase.class);
        cfg.addClass(PersonEncounterStatusType.class);
        cfg.addClass(JobCandidateStatusType.class);
        cfg.addClass(JobCandidateStatus.class);
        cfg.addClass(RecruitCompanyInfo.class);
        cfg.addClass(ResumeScanCriteria.class);
        cfg.addClass(ResumeScanBatchJob.class);
        cfg.addClass(ResumeScanResult.class);
        cfg.addClass(ResumeScanBatch.class);
        cfg.addClass(CompanyAddressType.class);
        cfg.addClass(CompanyAddress.class);
        cfg.addClass(PersonAddressType.class);
        cfg.addClass(PersonAddress.class);
        cfg.addClass(ServiceRequest.class);
        cfg.addClass(Skill.class);
        cfg.addClass(Resume.class);
        cfg.addClass(InterviewInstance.class);
        cfg.addClass(Interview.class);
        cfg.addClass(CandidateInfo.class);
        cfg.addClass(JobAgent.class);
        cfg.addClass(JobUserRole.class);
        
        // <!-- Exchange -->
        cfg.addClass(Accrued.class);
        cfg.addClass(Confirmation.class);
        cfg.addClass(Exchange.class);
        cfg.addClass(ExchangeItem.class);
        cfg.addClass(Referring.class);
    }

    @Override
    protected String getTestConnectionUrl() {
        return CoreServiceLocator.getConfiguration().getTestDatabaseUrl();
    }

}